package com.mvc.frame.sys;

import java.util.HashMap;
import java.util.Map;

public class AjaxResult {

	public Map<String, Object> ajaxResultSuccess() {
		return ajaxResultSuccess(null, null);
	}

	public Map<String, Object> ajaxResultSuccess(String info) {
		return ajaxResultSuccess(info, null);
	}

	public Map<String, Object> ajaxResultSuccess(Object data) {
		return ajaxResultSuccess("操作成功", data);
	}

	public Map<String, Object> ajaxResultFailure(String info) {
		return ajaxResultFailure(info, "");
	}

	public Map<String, Object> ajaxResultFailure(String info, Exception e) {
		return ajaxResultFailure(info + "发生系统错误:" + e.getLocalizedMessage() + ",请联系管理人员！", "");
	}

	public Map<String, Object> ajaxResultFailure(Exception e) {
		return ajaxResultFailure("发生系统错误:" + e.getLocalizedMessage() + ",请联系管理人员！", "");
	}

	public Map<String, Object> ajaxResultSuccess(String info, Object data) {
		return ajaxResultJson(1, info, data);
	}

	public Map<String, Object> ajaxResultFailure(String info, Object data) {
		return ajaxResultJson(0, info, data);
	}

	public Map<String, Object> ajaxResultJson(Integer code, String info, Object data) {
		info = info == null ? "操作成功" : info;
		data=data==null?"":data;
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("code", code);
		result.put("info", info);
		result.put("data", data);
		return result;
	}
}
